package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-12-23
 * Time:20:42
 */
public class ReturnOpearation implements IOPearation{
    @Override
    public void work(BookList bookList) {
        System.out.println("返回图书!!!");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要归还的书的书名!");
        String name = scanner.nextLine();

        int size = bookList.getUsedSize();
        for (int i = 0; i < size; i++) {
            Book book = bookList.getBook(i);
            if (book.getName().equals(name)){
                if (book.isIsborrowed()) {
                    book.setIsborrowed(false);
                    System.out.println("归还成功!");
                    return;
                }
            }
        }
        System.out.println("归还失败!");
    }
}
